package InfoGroup
{
	import Button.UglyTextField;
	
	import InfoGroup.SectorDeltaX;
	
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	import flashx.textLayout.formats.Float;

	public final class SectorOutputData extends Sprite
	{
		private var _title : TextField = new TextField();
		private var _titleFormat : TextFormat = new TextFormat();
		
		private var _sectorNumber : int = 0;
		public var timeStopedField : UglyTextField;
		
		public var totalTimeField : UglyTextField;
		
		//The DeltaXs		
		private var _deltaXsVector : Vector.<SectorDeltaX> = new Vector.<SectorDeltaX>;
		
		private var _showTTime : Boolean = false;
		
		public function SectorOutputData()
		{
			_title.x = 200;
			_title.y = -20;
			_titleFormat.size = 20;
			_titleFormat.bold;
			_titleFormat.align = TextFormatAlign.CENTER;
			_title.defaultTextFormat = _titleFormat;
			
			setSectorNumber(_sectorNumber);
			
			addChild(_title);
			
			timeStopedField = new UglyTextField(TextFieldType.DYNAMIC, 10, 50);
			timeStopedField.addLabel("T.Detencion", "Top");
			timeStopedField.addLabel("Hr", "Right");
			addChild(timeStopedField);
			
			totalTimeField = new UglyTextField(TextFieldType.DYNAMIC, 170, 50);
			totalTimeField.addLabel("T.Total Recor", "Top");
			totalTimeField.addLabel("Hr", "Right");
			//addChild(totalTimeField);
		}		 
		
		public function showTotalTime(show : Boolean) : void
		{
			if(!_showTTime && show)
			{
				addChild(totalTimeField);
				_showTTime = true;
			}
			else if(_showTTime && !show)
			{
				removeChild(totalTimeField);
				_showTTime = false;
			}
		}
		
		public function setSectorNumber(number:int) : void
		{
			_sectorNumber = number;
			_title.text = "SECTOR " + _sectorNumber;
		}
		
		public function getDeltaXList() : Vector.<SectorDeltaX>
		{
			return _deltaXsVector;
		}		
		
		public function addDeltaX(deltaXNumber:int, vel:Number, tiempo:Number, acel:Number, prog:Number) : void
		{
			var yOffset : int = 50;
			
			var tmpDeltaX : SectorDeltaX = new SectorDeltaX(deltaXNumber);
			tmpDeltaX.velocidad.setText((String)(vel * 3.6)); //paso de m/s a km/h
			tmpDeltaX.tiempo.setText((String)(tiempo/3600));//paso de segundos a hs
			tmpDeltaX.acel.setText((String)(acel));
			tmpDeltaX.progresiva.setText((String)(prog / 1000));//paso de m a km
			
			var lenght : int = _deltaXsVector.length;
			
			if(lenght > 0)
				tmpDeltaX.y = _deltaXsVector[lenght - 1].y + yOffset;
			else
				tmpDeltaX.y = yOffset;
			
			//Add to the vector
			_deltaXsVector.push(tmpDeltaX);
			//Add to the screen
			addChild(tmpDeltaX);
			
			timeStopedField.y = tmpDeltaX.y + yOffset + 20;
			totalTimeField.y = tmpDeltaX.y + yOffset + 20;
		}
		
		public function clearDeltaXList() : void
		{			
			for(var i:int = 0; i < _deltaXsVector.length; i++)
			{
				removeChild(_deltaXsVector[i]);
			}
			
			removeChild(timeStopedField);			
			//removeChild(totalTimeField);
			showTotalTime(false);
			
			_deltaXsVector.splice(0, _deltaXsVector.length);			
		}
	}	
}